package com.suray.wcs.service.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.suray.basic.wcs.utils.IBaseEnum;

import java.io.Serializable;

public enum TaskPlcProgress implements IBaseEnum<Serializable> {
    /**
     * 等待入库任务分配设备
     */
    WAIT(0, "等待"),
    /**
     * 入库设备已分配（指开启入库设备线程）
     */
    IN_DEVICE_ASSIGNED(10, "入库设备已分配"),
    /**
     * 外形检测完成
     */
    SHAPE_DETECTION(11, "外形检测完成"),
    /**
     * 扫码完成
     */
    IN_SCAN_CODE(12, "入库扫码完成"),
    /**
     * 称重完成
     */
    WEIGH(13, "称重完成"),
    /**
     * 已向WMS申请任务
     */
    APPLY_TASK(20, "已向WMS申请任务"),
    /**
     * 已向PLC申请任务
     */
    IN_APPLY_HOIST(25, "入库已向PLC申请提升机"),
    /**
     * 出库设备已分配
     */
    OUT_DEVICE_ASSIGNED(50, "出库设备已分配"),
    /**
     * 出库已向PLC申请提升机
     */
    OUT_APPLY_HOIST(51, "出库已向PLC申请提升机"),
    /**
     * 出库扫码完成
     */
    OUT_SCAN_CODE(51, "出库扫码完成"),

    /**
     * 所有设备任务完成(仅指设备，除小车)
     */
    ALL_DEVICE_COMPLETE(-90, "所有设备完成");
    @EnumValue
    private int taskProgress;
    @JsonValue
    private String description;

    TaskPlcProgress(int taskProgress, String description) {
        this.taskProgress = taskProgress;
        this.description = description;
    }

    @Override
    public String toString() {
        return description;
    }

    public static TaskPlcProgress parseTaskProgress(int taskProgress) {
        TaskPlcProgress[] taskProgresses = TaskPlcProgress.values();
        for (TaskPlcProgress progress : taskProgresses) {
            if (progress.taskProgress == taskProgress) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度参数异常");
    }

    public static TaskPlcProgress getByTaskProgress(int taskProgress) {
        TaskPlcProgress[] taskProgresses = TaskPlcProgress.values();
        for (TaskPlcProgress progress : taskProgresses) {
            if (progress.taskProgress == taskProgress) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度参数异常");
    }

    public static TaskPlcProgress parseTaskProgress(String description) {
        TaskPlcProgress[] taskProgresses = TaskPlcProgress.values();
        for (TaskPlcProgress progress : taskProgresses) {
            if (progress.description.equals(description)) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度描述异常");
    }

    public int getProgressNum() {
        return taskProgress;
    }

    @Override
    public Serializable getValue() {
        return taskProgress;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public Integer getVal() {
        // TODO Auto-generated method stub
        return null;
    }

}
